<template lang="pug">
	item(
		v-bind:d="d"
		track-by="gid"
	)
	br
	include /pugs/setting.pug
</template>
<script>

	const _ = require('lodash')

	module.exports = {
		mixins: [
			require('mixin/options/index'),
		],
		components: {
			item       : require('components/item'),
			numberInput: require('components/numberInput'),
		},
		data () {
			return {
				disableOptions: [
					'dry-run',
					'metalink-base-uri',
					'parameterized-uri',
					'pause',
					'piece-length',
					'rpc-save-upload-metadata',
					// --
					'log',
					'max-concurrent-downloads',
					'server-stat-of',
					'save-cookies',
					'bt-max-open-files',
					'max-overall-upload-limit',
					'rpc-save-upload-metadata',
					'download-result',
					'keep-unfinished-download-result',
					'log-level',
					'max-download-result',
					'max-overall-download-limit',
					'optimize-concurrent-downloads',
				],
				disableTabs: [
					'Metalink',
					'RPC',
				],
			}
		},
		methods: {
			submit () {
				this.changeOption(this.$route.query.gid, this.options)
					.then(res => {
						if (res.data.result !== 'OK') return

						this.schema.save()

						this.$router.go({
							name: 'index',
						})
					})
			},
		},
		events: {
			frame: _.throttle(
				/**
				 * @this
				 */
				function () {
					this.tellStatus(this.$route.query.gid)
						.then(item => {
							this.$set('d', item)
						})
				},
				1000
			),
		},
		ready () {
			this.getOption(this.$route.query.gid)
				.then(options => {
					this.schema.iterOption(option => {
						option.value = options[option.name]
					})
				})
		},
		detached () {
			this._events.frame.forEach(x => x.cancel())
		},
	}
</script>